package com.health.manage.controller;


import com.health.manage.token.CurrentUser;
import com.health.manage.token.OperatorAware;
import org.springframework.context.annotation.Scope;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Optional;


@Scope("prototype")
public abstract class BaseController {

    protected HttpServletRequest request;
    protected HttpServletResponse response;

    protected CurrentUser currentUser() {

        Optional<CurrentUser> optional = OperatorAware.getCurrentUser();
        CurrentUser currentUser = optional.orElse(null);
        if (currentUser == null || currentUser.getId() == null) {
            return null;
        }
        return currentUser;
    }

}
